package com.cyj.springmvc1.controller;

import com.cyj.springmvc1.entity.User;
import com.cyj.springmvc1.entity.Vo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021-03-06 10:27
 **/
@Controller
public class UserController {

    @RequestMapping("test1")
    public String test1() {
        System.out.println("tset1 run ....");
        return "index.jsp";
    }

    @RequestMapping("test2")
    @ResponseBody
    public String test2() throws JsonProcessingException {
        System.out.println("tset2 run ....");
        User user = new User().setUserName("cao");
        String json = new ObjectMapper().writeValueAsString(user);
        return json;
    }

    @RequestMapping("test3")
    @ResponseBody
    public List<User> test3() {
        System.out.println("tset3 run ....");
        User user = new User().setUserName("曹逸剑");
        List<User> userList = Arrays.asList(user);
        return userList;
    }

    @RequestMapping("test4")
    @ResponseBody
    public void test4(@RequestBody Vo vo) {
        System.out.println(vo);
    }
}
